package com.qinyunkj.searchchatserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qinyunkj.searchchatserver.mapper.CrawlerConfigMapper;
import com.qinyunkj.searchchatserver.model.entity.CrawlerConfig;
import com.qinyunkj.searchchatserver.service.CrawlerConfigService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class CrawlerConfigServiceImpl extends ServiceImpl<CrawlerConfigMapper, CrawlerConfig> implements CrawlerConfigService {

    @Override
    public CrawlerConfig getEnabledConfig() {
        LambdaQueryWrapper<CrawlerConfig> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CrawlerConfig::getEnabled, true)
              .last("LIMIT 1");
        return getOne(wrapper);
    }

    @Override
    public void updateLastExecuteTime(Long configId) {
        CrawlerConfig config = new CrawlerConfig();
        config.setId(configId);
        config.setLastExecuteTime(LocalDateTime.now());
        updateById(config);
    }
} 